define(function(){
	
	/**
	 * 验证手机号
	 */
	function isMobile(value) {
		return (/^(13|14|15|17|18)\d{1}\d{5}(\d{3}|\*{3})$/.test($.trim(value)));
	}
	
	//邮件地址字符
	function emailchar(value){
		return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($.trim(value));
	}
	
	//家庭电话，web金领的电话校验，放宽要求
	function isIcsTel(value){
		var reg = /^[0-9+-]{7,}$/;
		return reg.test($.trim(value));
	}
	
	//只能录入数字
	function isNumValidate (value){
		return /^[0-9]+$/.test($.trim(value));
	}

	//地址类字符校验
	function addressCharValidate(value){
		var reg1 = /(?:\?|\s|#|？|＃|€)/;
		return !reg1.test($.trim(value));
	}
	
	//校验小数位数
	function maxdotlength(value,params){
		var index = value.indexOf(".");
		index = index < 0 ? index : $.trim(value).length - 1 - index;
		return index <= params[0];
	}
	
	//是否浮点数或正整数
	function isFloatOrInteger(value,params){
		return isPositiveInteger($.trim(value)) || (/^([1-9]\d*|0)\.\d*[1-9]$/.test($.trim(value)));
	}
	
	//字母和空格（用于姓名拼音）
	function lettersblanks(value,params){
		return /^[A-Za-z\s]*$/.test($.trim(value));
	}
	
	//微博号
	function isBlogNum(value,params){
		return isChinese($.trim(value)) || (/^[A-Za-z0-9_\u4E00-\u9FBF\u3400-\u4DBF\ue815-\ue864]+$/.test($.trim(value))) || (/^[A-Za-z0-9]*$/.test($.trim(value))) || (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($.trim(value))) || (/^(\+\d{2}-)?(13|14|15|17|18)\d{1}\d{5}(\d{3}|\*{3})$/.test($.trim(value)));
	}
	
	function getStringLength(strItem){
		var count =0;
		for (var i=0; i<strItem.length; i++) {
			if (strItem.charCodeAt(i)>=256) {
		      		count+=2;
		   	} else {
		      		count+=1;
		    }
		}
		return count;
	}
	
	//生日格式校验
	function isCorrectBirthDay(value){
	   var birthStr = $.trim(value);
	   if(!birthStr){
	       return false;
	   }
	   if(!(/^\d{4}-\d{2}-\d{2}$/.test($.trim(value)))){
	       return false;
	   }
	   var year = parseInt(birthStr.substring(0,4),10);
	   var month = parseInt(birthStr.substring(5,7),10); 
	   var day =  parseInt(birthStr.substring(8,10),10);
	   if(year > new Date().getFullYear()){
	       return false;
	   }
	   if(month <0 || month >12){
	       return false;
	   }
	   if(day <0 || day >31){
	       return false;
	   }
	   return true;
    }

	
	/*********************************************
	 * 功能:校验是否由整数组成
	 * 参数:无
	 * 返回:无
	 **********************************************/
	function isPositiveInteger(s) {
	  var patrn=/^[1-9]\d*$/;
	  if (!patrn.exec(s)) {
		  return false;
	  }
	  return true;
	}
	
	/*********************************************
	 * 功能:校验字符串长度是否符合要求（汉字占两个字符）
	 * 参数:无
	 * 返回:ture || false
	 **********************************************/
	function byteRangeLength(value,minLen,maxLen,keyWord){
		if(!byteRangeLengthNoTip(value,minLen,maxLen)){
			wrapView.FlipPrompt.alert({"content":keyWord+"为"+minLen+"至"+maxLen+"个字符（汉字占两个字符）!"});
			return false;
		}else{
			return true;
		}
	}
	
	/*********************************************
	 * 功能:校验字符串长度是否符合要求（汉字占两个字符）
	 * 参数:无
	 * 返回:ture || false
	 **********************************************/
	function byteRangeLengthNoTip(value,minLen,maxLen){
		var len = getCHLength($.trim(value));
		if(len >= minLen && len <= maxLen){
			return true;
		}else{
			return false;
		}
	}
	
	/*********************************************
	 * 功能:校验字符串长度是否符合要求（汉字占两个字符）
	 * 参数:无
	 * 返回:ture || false
	 **********************************************/
	function byteMaxRangeLength(value,maxLen,keyWord){
		var len = getCHLength($.trim(value));
		if(len <= maxLen){
			return true;
		}else{
			PAWA.CommonTools.alertCommon("温馨提示",keyWord+"长度不能超过"+Math.ceil(maxLen/2)+"个汉字!");
			return false;
		}
	}
	
	/*********************************************
	 * 功能:替换字符串
	 * 参数:无
	 * 返回:替换后的字符串
	 **********************************************/
	function replace(str,searchStr) 
	 { 
	 	 if(str == null || str == ""){
	 	 		return "";
	 	 }
	    var re=new RegExp(searchStr,"g"); 
	    var newstr=str.replace(re,""); 
	    return newstr; 
	 } 
	
	/*********************************************
	 * 功能:清除不合法的手机格式
	 * 参数:无
	 * 返回:返回合法的手机号码
	 **********************************************/
	function clearFormatForPhone(phoneNum){
	 	if(phoneNum == null ||  phoneNum == ""){
	 		return "";
	 	}
	 	if(phoneNum.length < 11){
	 		return phoneNum;
	 	}
	 	if(phoneNum.substring(0,2) == "86"){
	 		phoneNum = phoneNum.substring(2,phoneNum.length);
	 		
	 	}else if(phoneNum.substring(0,3) == "+86"){
	 		phoneNum = phoneNum.substring(3,phoneNum.length);
	 	}
	 	phoneNum = replace(phoneNum,"-");
	 	return phoneNum;
	}
	
	function formatTel(clientTel){
		if(clientTel){
			if(clientTel.substring(0,2) == "86"){
		 		clientTel = clientTel.substring(2,clientTel.length);
		 		
		 	}else if(clientTel.substring(0,3) == "+86"){
		 		clientTel = clientTel.substring(3,clientTel.length);
		 	}
		 	
		 	if(clientTel.substring(0,1) === "-"){
		 		clientTel = clientTel.substring(1,clientTel.length);
		 	}
		 	
		 	return "0" + clientTel;
		}
		return "";
	}
	
	
	/*********************************************
	 * 功能:姓名校验_是否含有非法字符
	 * 参数:无
	 * 返回:ture || false
	 **********************************************/
	function nameCharValidate(value,errMsg){
		value = $.trim(value);
		if(value == '不详' || value == '不祥' || value == '未知' ||value == '不知道' ){
			wrapView.FlipPrompt.alert({"content":errMsg});
			return false;
		}else{
			var hasChinese = false;
			for(var i = 0;i < value.length;i++){
				var c = value.charAt(i);
				if (isChinese(c)){
					hasChinese = true;
					continue;
				}
				if(c == ' '){
					continue;
				}
				
				if (c == '.' || c == '·' || c == '．' ){
					if(i == 0 || i == value.length - 1){
						wrapView.FlipPrompt.alert({"content":errMsg});
						return false;
					}else{
						if(hasChinese){
							if(c == '·'){
								continue;
							}else{
								wrapView.FlipPrompt.alert({"content":errMsg});
								return false;
							}
						}else{
							continue;
						}
					}
				}

				var code = value.charCodeAt(i);
				if (code >= 65 && code <= 90)//只接受大写字母
					continue;
				wrapView.FlipPrompt.alert({"content":errMsg});
				return false;
				
			}
		}
		return true;
	}
	
	/*********************************************
	 * 功能:是否全角(双字节字符)
	 * 参数:无
	 * 返回:无
	 **********************************************/
	function is2Bytes(s){
	  var patrn = /[^\x00-\xff]/;
	  if (!patrn.test(s)) {
		  return false;
	  }
	  return true;
	}
	
	/*********************************************
	 * 功能:校验是否由汉字组成(不包括其它全角符号)
	 * 参数:无
	 * 返回:无
	 **********************************************/
	function isChinese(s) {
		var chinesePatrn1 = /^[\u4E00-\u9FBF]+$/;
		var chinesePatrn2 = /^[\u3400-\u4DBF]+$/;
		var chinesePatrn3 = /^[\ue815-\ue864]+$/;
		return chinesePatrn1.test(s) ? true : (chinesePatrn2.test(s) ? true : chinesePatrn3.test(s));
	}
	
	/*********************************************
	 * 功能:获取字符串长度（汉字占两个字符）
	 * 参数:无
	 * 返回:
	 **********************************************/
	function getCHLength(value){
		value = $.trim(value);
		var count = 0;
		
		if (value && value.length){
			for(var i = 0;i < value.length;i++){
				if (is2Bytes(value.charAt(i)))
					count += 2;
				else
					count += 1;
			}
		}
		return count;
	}
	
	/*********************************************
	 * 功能:验证15位 18位身份证，可以验证到最后一位
	 * 参数:身份证号码
	 **********************************************/
	 function checkIdcard2(idcard) {
		var Errors = new Array("验证通过!", "身份证号码位数不对!", "身份证号码出生日期超出范围或含有非法字符!",
				"身份证号码校验错误!", "身份证地区非法!");
		var area = {
			11 : "北京",
			12 : "天津",
			13 : "河北",
			14 : "山西",
			15 : "内蒙古",
			21 : "辽宁",
			22 : "吉林",
			23 : "黑龙江",
			31 : "上海",
			32 : "江苏",
			33 : "浙江",
			34 : "安徽",
			35 : "福建",
			36 : "江西",
			37 : "山东",
			41 : "河南",
			42 : "湖北",
			43 : "湖南",
			44 : "广东",
			45 : "广西",
			46 : "海南",
			50 : "重庆",
			51 : "四川",
			52 : "贵州",
			53 : "云南",
			54 : "西藏",
			61 : "陕西",
			62 : "甘肃",
			63 : "青海",
			64 : "宁夏",
			65 : "新疆",
			71 : "台湾",
			81 : "香港",
			82 : "澳门",
			91 : "国外"
		}
		var idcard, Y, JYM;
		var S, M;
		var idcard_array = new Array();
		idcard_array = idcard.split("");
		// 地区检验
		if (area[parseInt(idcard.substr(0, 2),10)] == null) {
			PAWA.CommonTools.alertCommon("温馨提示",Errors[4]);
			return false;
		}

		// 身份号码位数及格式检验
		switch (idcard.length) {
		case 15:
			if ((parseInt(idcard.substr(6, 2),10) + 1900) % 4 == 0
					|| ((parseInt(idcard.substr(6, 2,10)) + 1900) % 100 == 0 && (parseInt(idcard
							.substr(6, 2),10) + 1900) % 4 == 0)) {
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;// 测试出生日期的合法性
			} else {
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;// 测试出生日期的合法性
			}
			if (ereg.test(idcard)) {
				return true;
			} else {
				PAWA.CommonTools.alertCommon("温馨提示",Errors[2]);
				return false;
			}
			break;
		case 18:
			// 18位身份号码检测
			// 出生日期的合法性检查
			// 闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
			// 平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
			if (parseInt(idcard.substr(6, 4),10) % 4 == 0
					|| (parseInt(idcard.substr(6, 4),10) % 100 == 0 && parseInt(idcard
							.substr(6, 4),10) % 4 == 0)) {
				ereg = /^[1-9][0-9]{5}(19|[2-9][0-9])[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;// 闰年出生日期的合法性正则表达式
			} else {
				ereg = /^[1-9][0-9]{5}(19|[2-9][0-9])[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;// 平年出生日期的合法性正则表达式
			}
			if (ereg.test(idcard)) {// 测试出生日期的合法性
				// 计算校验位
				S = (parseInt(idcard_array[0],10) + parseInt(idcard_array[10],10))
						* 7
						+ (parseInt(idcard_array[1],10) + parseInt(idcard_array[11],10))
						* 9
						+ (parseInt(idcard_array[2],10) + parseInt(idcard_array[12],10))
						* 10
						+ (parseInt(idcard_array[3],10) + parseInt(idcard_array[13],10))
						* 5
						+ (parseInt(idcard_array[4],10) + parseInt(idcard_array[14],10))
						* 8
						+ (parseInt(idcard_array[5],10) + parseInt(idcard_array[15],10))
						* 4
						+ (parseInt(idcard_array[6],10) + parseInt(idcard_array[16],10))
						* 2 + parseInt(idcard_array[7],10) * 1
						+ parseInt(idcard_array[8],10) * 6
						+ parseInt(idcard_array[9],10) * 3;
				Y = S % 11;
				M = "F";
				JYM = "10X98765432";
				M = JYM.substr(Y, 1);// 判断校验位
				if (M == idcard_array[17]) {
					return true; // 检测ID的校验位
				} else {
					PAWA.CommonTools.alertCommon("温馨提示",Errors[3]);
					return false;
				}
			} else {
				PAWA.CommonTools.alertCommon("温馨提示",Errors[2]);
				return false;
			}
			break;
		default:
			PAWA.CommonTools.alertCommon("温馨提示",Errors[1]);
			return false;
			break;
		}
	}
	 
	 /***************************************************************************
	 * 功能:根据身份证返回yyyy-MM-dd格式的日期
	 **************************************************************************/
	function getBirthdayFromIdNo2(val) {
		val = $.trim(val);
		var birthdayValue;
		if (15 == val.length) { // 15位身份证号码
			birthdayValue = val.substr(6, 2);
			if (parseInt(birthdayValue, 10) < 10) {
				birthdayValue = '20' + birthdayValue;
			} else {
				birthdayValue = '19' + birthdayValue;
			}
			birthdayValue = birthdayValue + '-' + val.substr(8, 2) + '-'
					+ val.substr(10, 2);
		}
		if (18 == val.length) { // 18位身份证号码
			birthdayValue = val.substr(6, 4) + '-' + val.substr(10, 2) + '-'
					+ val.substr(12, 2);
		}
		return birthdayValue;
	}
	
	/***************************************************************************
	 * 功能:校验客户中心标签名是否合法（可以包含汉字和半角的数字、字母和符号） 参数:无 返回:无
	 **************************************************************************/
	function validateLabelNameChar(labelName){
		for(var i = 0;i < labelName.length;i++){
			var c = labelName.charAt(i);
			if(is2Bytes(c)&&!isChinese(c)){
				return false;
			}
		}		
		return true;
	}
	
	/**
	 * 校验标签的合法性
	 */
	function isValidClientLabel(labelName){
		var trimedLabelName = $.trim(labelName);
		if(trimedLabelName==''){
			PAWA.CommonTools.alertCommon("温馨提示","标签名不能为空,请修改。");
			return false;
		}else if(getCHLength(trimedLabelName)>20){
			PAWA.CommonTools.alertCommon("温馨提示","标签名不能超过20个字符（一个汉字为2个字符），请修改。");
			return false;
		}else if(!validateLabelNameChar(trimedLabelName)){
			PAWA.CommonTools.alertCommon("温馨提示","标签名只能包含中文以及半角的数字、字母和符号，请修改。");
			return false;
		}
		return true;
	}
	/**
	 * 和上面方法一样,用Flayer返回提示信息
	 */
	function isValidClientLabelReturnFlayer(labelName){
		var trimedLabelName = $.trim(labelName);
		if(trimedLabelName==''){
			wrapView.FlipPrompt.Flayer("标签名不能为空,请修改。",true,1000,1);
			return false;
		}else if(getCHLength(trimedLabelName)>20){
			wrapView.FlipPrompt.Flayer("标签名不能超过20个字符（一个汉字为2个字符），请修改。",true,1000,1);
			return false;
		}else if(!validateLabelNameChar(trimedLabelName)){
			wrapView.FlipPrompt.Flayer("标签名只能包含中文以及半角的数字、字母和符号，请修改。",true,1000,1);
			return false;
		}
		return true;
	}
	
	/* @author ex-zhengzongyi001
	 * @description 转换阿拉伯数字为中文大写数字
	 * @example arabicToChinese(123) -> "壹佰贰拾叁"
	 * @param {string, number} number
	 * @return {string} result
	 */
	function arabicToChinese(number){
        var chineseNum = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾"];
        var chineseUnit = ["", "拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万","拾","佰","仟"];
        
	    if(/^\s*$/.test(number)) return "";
	    if(isNaN(Number(number))) return "";
	    if(/e/.test(Number(number) + "")) return ""; // scientific notation
        
	    number = parseInt(Number(number),10).toString();
	    if(number.length > 15) return "";
	    if(number == "0") return chineseNum[0];
        
        var result = "";
        for(var i = 0, len = number.length; i < len; i++){
            result += chineseNum[number.charAt(i)] + chineseUnit[len - i - 1];
        }
        
        result = result
            .replace(/(?:零[拾佰仟])+/g, "零")
            .replace(/亿零*万/, "亿")
            .replace(/零+([万亿])/g, "$1零")
            .replace(/零+/g, "零")
            .replace(/^(.+?)零*$/, "$1");
            
        return result;
    }
	
    /*
     * @author    EX-ZHENGZONGYI001
     * @description   转换一个阿拉伯数字成中文大写数字
     * @example    convertToCHNumber("10001") --> 壹万零壹元整
     * @param {string} sAmount 	input
     * @return {string} result 
     */
	function convertToCHNumber(number){
		number = number.toString().trim();
		number = number.replace(/^[-+]/, "");
		if(!number || isNaN(number)) return "";
		
		number = "0" + number;
		number = number.indexOf(".") < 0 ? number + ".00" : number + "00";
		number = number.replace(/^(?:0(?!\.))*(\d+\.\d\d)\d*$/, "$1");
		number = number.replace(".", "");
		number = number.replace(/0*(\d+)$/, "$1");
		
		if(!/^\d+$/.test(number)) return "";
		if(number.length > 17) return "";
		if(/^0+$/.test(number)) return "零元";

		var chineseNum = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾"];
	    var chineseUnit = ["分","角","元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万","拾","佰","仟"];
	    
	    var result = "";
	    for (var i = 0; i < number.length; i++){
	        result += chineseNum[number.charAt(i)] + chineseUnit[number.length - i - 1];
	    }
	
	    result = result
	        .replace(/(?:零[分角拾佰仟])+/g, "零")
	        .replace(/零+([元万亿])/g, "$1")
	        .replace(/亿零*万/, "亿")
	        .replace(/([万亿])零+元/, "$1元")
	        .replace(/零+/g, "零")
	        .replace(/零*$/, "")
	        .replace(/^元零+/, "")
	        .replace(/元$/, "元整")
	
	    return result;
	}
	
	

	var currencyMap = [
		["01", "人民币", "RMB"],
		[undefined, "人民币", "CNY"],
		["23", "欧元", "EUR"],
		["28", "加拿大元", "CAD"],
		["13", "港币", "HKD"],
		["27", "日元", "JPY"],
		["15", "瑞士法郎", "CHF"],
		["14", "美元", "USD"],
		["18", "新加坡元", "SGD"],
		["29", "澳大利亚元", "AUD"],
		["12", "英镑", "GBP"],
		[undefined, "澳门元", "MOP"],
		[undefined, "马克", "DEM"],
		[undefined, "法郎", "FRF"]
	];
	
	var currencyMap2 = [
		["156", "人民币"],
		["250", "马克"],
		["256", "法郎"],
		["344", "港元"],
		["392", "日元"],
		["826", "英镑"],
		["840", "美元"],
		["954", "欧元"]
	];
		
	
	/*
     * @author    EX-ZHENGZONGYI001
     * @description   根据货币代码(s)或货币简写获取货币名称(s)
     * @example    getCurrencyName("01") --> "人民币"
     * @example    getCurrencyName("rmb") --> "人民币"
     * @example    getCurrencyName("0123") --> "人民币,欧元"
     * @param {string} code	货币代码或货币简写
     * @param {non-false} useMap2 默认false,当为非false值时，使用另一个map(该map人民币代码为156)  
     * @return {string} result 
     */
	function getCurrencyName(code, useMap2){
		// TODO deep
		function getName(value, map, key){
			for(var len = map.length; len--;){
				if(map[len][key] === value) return map[len][1];
			}
		}
		
		code = code || "";
		code = code.toString().toUpperCase();
		
		if(code.length < 2) return "";
		
		// if use map2, then get name by code always
		if(useMap2) return getName(code, currencyMap2, 0);
		
		// by shortName(rmb, eur, cad etc..)
		if(!/\d+/.test(code)) return getName(code, currencyMap, 2) || "";
		
		// by single code
		if(code.length === 2) return getName(code, currencyMap, 0) || "";
		
		// by mutiple codes, returns names
		var ret = [], val;
		for(var i = 0, len = code.length; i < len; i += 2){
			if(val = getCurrencyName(code.substr(i, 2))) ret.push(val);
		}
		return ret.join();
	}
	
	/*
     * @author    EX-ZHENGZONGYI001
     * @description   根据货币名称(s)获取货币代码(s)
     * @example    getCurrencyCode("人民币") --> "01"
     * @example    getCurrencyName("人民币,欧元") --> "0123"
     * @param {string} names	货币名称(s)
     * @return {string} result 货币代码(s)
     */	
	function getCurrencyCode(names){
		// TODO deep
		var ret = "";
		var names = names.split(",");
		var map = currencyMap;
		
		for(var i = 0; i < names.length; i++){
			var name = names[i];
			for(var k = 0; k < map.length; k++){
				if(map[k][1] == name) ret += map[k][0];
			}
		}
		
		return ret;
	}
	
	
	
	/*
     * @author    EX-HUXINWU001
     * @description   将当前key、value组装成xml
     * @param {string} key   
     * @return {string} value
     */
	function format2Xml(key, value) {
		var res = "";
		if (key != null && key != "") {
			if (value == null || value == undefined) {
				value = "";
			}
			res = "<" + key + ">" + "<![CDATA[" + value + "]]>" + "</" + key + ">";
		}
		return res;
	}
	
	/*********************************************
	 * 功能:检验客户的证件如果是身份证时，一代身份证的校验
	 * 参数:idNo：		证件号码
	 * 返回:如果为一代身份证（证件长度为15），返回false，否则返回true
	 * author: chengyi316
	 **********************************************/
	function checkIdentityCard(idCard){
		var result = true;
		if(15 == idCard.length){
			result = false;
		}
		return result;
		
	}
	
	function   checkIdcard(idcard){
	       
        var   area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",
                    22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",
                    35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",
                    44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",
                    53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",
                    65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"
                     }
        var   idcard,Y,JYM;
        var   S,M;
        var   idcard_array   =   new   Array();
        idcard_array   =   idcard.split("");
        // 地区检验
        if(area[parseInt(idcard.substr(0,2),10)]==null)
        {
             
             return false;
        }

        // 身份号码位数及格式检验
        switch(idcard.length){
          case   15:
          if   ((parseInt(idcard.substr(6,2),10)+1900)   %   4   ==   0   ||   ((parseInt(idcard.substr(6,2),10)+1900)   %   100   ==   0   &&   (parseInt(idcard.substr(6,2),10)+1900)   %   4   ==   0   )){
            ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;// 测试出生日期的合法性
          }
          else{
            ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;// 测试出生日期的合法性
          }
          if(ereg.test(idcard)){
            return true;
          }
          else {
            
            return false;
          }
          break;
          case   18:
          // 18位身份号码检测
          // 出生日期的合法性检查
          // 闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
          // 平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
          if(parseInt(idcard.substr(6,4),10)   %   4   ==   0   ||   (parseInt(idcard.substr(6,4),10)   %   100   ==   0   &&   parseInt(idcard.substr(6,4),10)%4   ==   0   )){
            ereg=/^[1-9][0-9]{5}(19|[2-9][0-9])[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;// 闰年出生日期的合法性正则表达式
          }
          else{
            ereg=/^[1-9][0-9]{5}(19|[2-9][0-9])[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;// 平年出生日期的合法性正则表达式
          }
          if(ereg.test(idcard)){// 测试出生日期的合法性
                // 计算校验位
                S   =   (parseInt(idcard_array[0],10)   +   parseInt(idcard_array[10],10))   *   7
                +   (parseInt(idcard_array[1],10)   +   parseInt(idcard_array[11],10))   *   9
                +   (parseInt(idcard_array[2],10)   +   parseInt(idcard_array[12],10))   *   10
                +   (parseInt(idcard_array[3],10)   +   parseInt(idcard_array[13],10))   *   5
                +   (parseInt(idcard_array[4],10)   +   parseInt(idcard_array[14],10))   *   8
                +   (parseInt(idcard_array[5],10)   +   parseInt(idcard_array[15],10))   *   4
                +   (parseInt(idcard_array[6],10)   +   parseInt(idcard_array[16],10))   *   2
                +   parseInt(idcard_array[7],10)   *   1
                +   parseInt(idcard_array[8],10)   *   6
                +   parseInt(idcard_array[9],10)   *   3   ;
                Y   =   S   %   11;
                M   =   "F";
                JYM   =   "10X98765432";
                M   =   JYM.substr(Y,1);// 判断校验位
                if(M   ==   idcard_array[17]){
                  return true;  // 检测ID的校验位
                }
                else {
                	
                  return false;
                }
          }
          else  {
          	
            return false;
          }
          break;
          default:
          	
            return false;
          break;
        }
  }
	 
	function isTel(value)
	{
	    //"兼容格式: 区号(3到4位)-电话号码(7到8位)-分机号(3位)"
	    return (/^(\+\d{2}-)?((0?\d{2,3})-)(\d{7,8})(-(\d{3}))?$/.test($.trim(value)));
	}

	function isNotEmpty(value){
		if(value==undefined){
			return false;
		}
		return !/^\s*$/.test(value);
	}
	function isAutoBusinessNo(value){
		return /^[a-zA-Z]{2}[0-9]{8,9}$/.test(value);
	}
	
	function isAutoCommissionerNo(value){
		return /^[0-9]{16}((19|20)[0-9]{2})[0-9]{6}$/.test(value);
	}
	
	function isDigit(value){//判断是否为数字
        var patrn=/^[0-9]+$/; 
        if(!patrn.exec(value)){
           return false;
        }
        return true;
    }
    
    function inRange(value,range){//判断数值范围
        return (value >= range[0] && value <= range[1]);
    }
	
	var exports = {};
	
	// exports tool methods
	exports.isTel=isTel;
	exports.checkIdcard=checkIdcard;
	exports.checkIdentityCard=checkIdentityCard;
	exports.checkIdcard2=checkIdcard2;
	exports.getBirthdayFromIdNo2=getBirthdayFromIdNo2;
	exports.convertToCHNumber = convertToCHNumber;
	exports.getCurrencyCode = getCurrencyCode;
	exports.getCurrencyName = getCurrencyName;
	exports.arabicToChinese = arabicToChinese;
	exports.format2Xml = format2Xml;
	exports.isValidClientLabel = isValidClientLabel;
	exports.isValidClientLabelReturnFlayer = isValidClientLabelReturnFlayer;
	exports.getCHLength = getCHLength;
	exports.byteRangeLength = byteRangeLength;
	exports.byteMaxRangeLength = byteMaxRangeLength;
	exports.byteRangeLengthNoTip = byteRangeLengthNoTip;
	exports.nameCharValidate = nameCharValidate;
	
	exports.isMobile = isMobile;
	exports.emailchar = emailchar;
	exports.isIcsTel = isIcsTel;
	exports.isNumValidate = isNumValidate;
	exports.addressCharValidate = addressCharValidate;
	exports.maxdotlength = maxdotlength;
	exports.isFloatOrInteger = isFloatOrInteger;
	exports.lettersblanks = lettersblanks;
	exports.isBlogNum = isBlogNum;
	exports.isCorrectBirthDay = isCorrectBirthDay;
	exports.clearFormatForPhone = clearFormatForPhone;
	exports.formatTel = formatTel;
	exports.replace = replace;
	exports.getStringLength = getStringLength;
	
	exports.isAutoBusinessNo=isAutoBusinessNo;
	exports.isAutoCommissionerNo=isAutoCommissionerNo;
	exports.isNotEmpty=isNotEmpty;
	
	exports.isDigit=isDigit;
	exports.inRange=inRange;
	
	return exports;
});
